package com.hjx.movie.core.system.controller.user;

import com.hjx.movie.common.utils.Result;
import com.hjx.movie.common.utils.ResultType;
import com.hjx.movie.core.system.service.user.IUserMovieService;
import com.hjx.movie.core.system.vo.OrderSubVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2021/3/20 - 16:16
 */
@Slf4j
@RestController
@RequestMapping("userOrder")
public class UserOrderController {

    @Resource
    IUserMovieService userMovieService;

    @PostMapping("/preOrderCheck")
    public Result preOrderCheck(@RequestBody OrderSubVO orderVO){
        String msg = "座位预占失败请选择其他的座位";
        if (!orderVO.getSeatIds().isEmpty()&&orderVO.getAccountId()!=null&&orderVO.getHallId()!=null){
            return Result.success(userMovieService.preOrderCheck(orderVO));
        }else {
            msg = "请选择座位";
        }
        return Result.error(ResultType.USER_INPUT_ERROR,msg);
    }

    @PostMapping("/order")
    public Result addOrder(@RequestBody OrderSubVO orderSubVO){
        if(userMovieService.addOrder(orderSubVO)){
            return Result.success("订票成功");
        }else {
            return Result.error(ResultType.USER_INPUT_ERROR,"订票失败");
        }
    }

    @GetMapping("/orders")
    public Result orderList(@RequestParam("aid") Long aid){
        return Result.success(userMovieService.findOrderByAccountId(aid) );
    }

    @GetMapping("/orderItems")
    public Result orderItemList(@RequestParam("oid") Long oid){
        return Result.success(userMovieService.findOrderItemByOrderId(oid) );
    }
}
